﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using System.Windows.Threading;
using Microsoft.Live;
using Microsoft.Live.Controls;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Tasks;
using Microsoft.Xna.Framework.Media;
using ShareFolder.ViewModel;

namespace ShareFolder
{
    public partial class Explorer : PhoneApplicationPage
    {

        private sealed class Class1
        {
            public Explorer explorer_0;
            public string string_0;
            private static Func<string, string> func_0;
            private static Func<string, string> func_1;
            public void method_0(object sender, DoWorkEventArgs e)
            {
                IEnumerable<string> arg_48_0 = this.explorer_0._isolatedStore.GetDirectoryNames("content\\" + this.string_0 + "\\*");
                if (Explorer.Class1.func_0 == null)
                {
                    Explorer.Class1.func_0 = new Func<string, string>(Explorer.Class1.smethod_0);
                }
                IOrderedEnumerable<string> orderedEnumerable = Enumerable.OrderBy<string, string>(arg_48_0, Explorer.Class1.func_0);
                IEnumerable<string> arg_90_0 = this.explorer_0._isolatedStore.GetFileNames("content\\" + this.string_0 + "\\*");
                if (Explorer.Class1.func_1 == null)
                {
                    Explorer.Class1.func_1 = new Func<string, string>(Explorer.Class1.smethod_1);
                }
                IOrderedEnumerable<string> orderedEnumerable2 = Enumerable.OrderBy<string, string>(arg_90_0, Explorer.Class1.func_1);
                this.explorer_0._localList.Clear();
                if (this.string_0 != null)
                {
                    GClass1 gClass = new GClass1();
                    gClass.FileName = "..";
                    gClass.ImageSrc = "/Images/folder.png";
                    gClass.IsDirectory = true;
                    gClass.Path = this.string_0;
                    this.explorer_0._localList.Add(gClass);
                }
                using (IEnumerator<string> enumerator = orderedEnumerable.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        string current = enumerator.Current;
                        GClass1 gClass2 = new GClass1();
                        gClass2.FileName = current;
                        gClass2.ImageSrc = "/Images/folder.png";
                        gClass2.IsDirectory = true;
                        gClass2.Path = this.string_0;
                        this.explorer_0._localList.Add(gClass2);
                    }
                }
                using (IEnumerator<string> enumerator2 = orderedEnumerable2.GetEnumerator())
                {
                    while (enumerator2.MoveNext())
                    {
                        string current2 = enumerator2.Current;
                        GClass1 gClass3 = new GClass1();
                        gClass3.FileName = current2;
                        gClass3.ImageSrc = "/Images/file.png";
                        gClass3.Path = this.string_0;
                        gClass3.FileSize = this.explorer_0.method_9("content\\" + this.string_0 + "\\" + current2);
                        this.explorer_0._localList.Add(gClass3);
                    }
                }
            }
            public void method_1(object sender, RunWorkerCompletedEventArgs e)
            {
                this.explorer_0.txtLocalLocation.Text = (this.string_0);
                this.explorer_0.lstBoxLocal.ItemsSource = (this.explorer_0._localList);
                this.explorer_0.pivotLocation.IsEnabled = (true);
            }
            private static string smethod_0(string string_1)
            {
                return string_1;
            }
            private static string smethod_1(string string_1)
            {
                return string_1;
            }
        }

        private sealed class Class2
        {
            public Explorer explorer_0;
            public PhotoResult photoResult_0;
        }

        private sealed class Class3
        {
            private sealed class Class4
            {
                private sealed class Class5
                {
                    public Explorer.Class3.Class4 class4_0;
                    public Explorer.Class3 class3_0;
                    public Explorer.Class2 class2_0;
                    public Exception exception_0;
                    public void method_0()
                    {
                        MessageBox.Show(this.exception_0.Message);
                    }
                }
                public Explorer.Class3 class3_0;
                public Explorer.Class2 class2_0;
                public Stream stream_0;
                public string string_0;
                public void method_0(object sender, DoWorkEventArgs e)
                {
                    Action action = null;
                    try
                    {
                        Dispatcher arg_23_0 = this.class2_0.explorer_0.Dispatcher;
                        if (action == null)
                        {
                            action = new Action(this.method_1);
                        }
                        arg_23_0.BeginInvoke(action);
                        if (this.class3_0.genum0_0 != GEnum0.const_2)
                        {
                            byte[] array = new byte[4096];
                            int num;
                            while ((num = this.class2_0.photoResult_0.ChosenPhoto.Read(array, 0, array.Length)) > 0)
                            {
                                this.stream_0.Write(array, 0, num);
                            }
                            this.stream_0.Dispose();
                        }
                        else
                        {
                            this.class2_0.explorer_0._skyDriveManager.method_13(this.class2_0.explorer_0._skyPathManager.method_4(), this.string_0, this.class2_0.photoResult_0.ChosenPhoto);
                        }
                    }
                    catch (Exception exception_)
                    {
                        Explorer.Class3.Class4.Class5 @class = new Explorer.Class3.Class4.Class5();
                        @class.class4_0 = this;
                        @class.class3_0 = this.class3_0;
                        @class.class2_0 = this.class2_0;
                        @class.exception_0 = exception_;
                        this.class2_0.explorer_0.Dispatcher.BeginInvoke(new Action(@class.method_0));
                    }
                }
                private void method_1()
                {
                    this.class2_0.explorer_0.pivotLocation.IsEnabled = (false);
                    this.class2_0.explorer_0.ApplicationBar.IsVisible = false;
                    this.class2_0.explorer_0.pbReading.Visibility = (Visibility)(0);
                    this.class2_0.explorer_0.pbReading.IsIndeterminate = true;
                }
            }
            public Explorer.Class2 class2_0;
            public GEnum0 genum0_0;
            public BackgroundWorker backgroundWorker_0;
            public void method_0(object sender, EventArgs e)
            {
                RunWorkerCompletedEventHandler runWorkerCompletedEventHandler = null;
                if (string.IsNullOrEmpty(this.class2_0.explorer_0.txtFileName.Text))
                {
                    MessageBox.Show("Please, enter a file name.");
                    return;
                }
                try
                {
                    Explorer.Class3.Class4 @class = new Explorer.Class3.Class4();
                    @class.class3_0 = this;
                    @class.class2_0 = this.class2_0;
                    @class.stream_0 = null;
                    @class.string_0 = this.class2_0.explorer_0.txtFileName.Text;
                    BackgroundWorker arg_82_0 = this.backgroundWorker_0;
                    if (runWorkerCompletedEventHandler == null)
                    {
                        runWorkerCompletedEventHandler = new RunWorkerCompletedEventHandler(this.method_1);
                    }
                    arg_82_0.RunWorkerCompleted += runWorkerCompletedEventHandler;
                    switch (this.genum0_0)
                    {
                        case GEnum0.const_0:
                            this.class2_0.explorer_0.method_5();
                            @class.stream_0 = new ab(this.class2_0.explorer_0._smb, this.class2_0.explorer_0._service, this.class2_0.explorer_0._remotePathManager.method_2() + "\\" + @class.string_0, 1);
                            break;
                        case GEnum0.const_1:
                            @class.stream_0 = this.class2_0.explorer_0._isolatedStore.OpenFile("content\\" + this.class2_0.explorer_0._localPathManager.method_2() + "\\" + @class.string_0, (FileMode)4);
                            break;
                        case GEnum0.const_2:
                            if (this.class2_0.explorer_0._skyDriveManager == null)
                            {
                                MessageBox.Show("Please, sign in on SkyDrive.");
                                return;
                            }
                            break;
                    }
                    this.backgroundWorker_0.DoWork += (new DoWorkEventHandler(@class.method_0));
                    this.backgroundWorker_0.RunWorkerAsync();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                this.class2_0.explorer_0.RenameCanvas.Visibility = (Visibility)1;
                this.class2_0.explorer_0.pivotLocation.Visibility = (Visibility)(0);
                this.class2_0.explorer_0.method_1();
            }
            private void method_1(object sender, RunWorkerCompletedEventArgs e)
            {
                this.class2_0.explorer_0.Dispatcher.BeginInvoke(new Action(this.method_2));
            }
            private void method_2()
            {
                MessageBox.Show("File successfully copied");
                this.class2_0.explorer_0.pbReading.Visibility = (Visibility)(1);
                this.class2_0.explorer_0.pbReading.IsIndeterminate = false;
                this.class2_0.explorer_0.pivotLocation.IsEnabled = (true);
                this.class2_0.explorer_0.ApplicationBar.IsVisible = true;
                this.class2_0.explorer_0.method_11();
            }
        }

        private bool _newPage = true;
        private aa _smb;
        private string _service;
        private GClass7 _remotePathManager = new GClass7();
        private GClass7 _localPathManager = new GClass7();
        private GClass7 _skyPathManager = new GClass7();
        private List<GClass1> _localList = new List<GClass1>();
        private List<GClass1> _remoteList = new List<GClass1>();
        private List<GClass2> _skyList;
        private GClass0 _clipboard;
        private GClass4 _pm;
        private GClass3 _dm;
        private IsolatedStorageFile _isolatedStore = IsolatedStorageFile.GetUserStoreForApplication();
        private GClass1 _fileToRename;
        private bool _iscopying;
        private bool _isLocalMode;
        private GClass5 _skyDriveManager;
        private bool _IsSignButtonClicked;
        private string _IsTrial;

        public Explorer()
        {
            this.InitializeComponent();

        }
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            Func<ConnectionViewModel, bool> func = null;
            if (this._newPage)
            {
                this.method_1();
                if (base.NavigationContext.QueryString.ContainsKey("ConnectionName"))
                {
                    if (!App.ViewModel.IsDataLoaded)
                    {
                        App.ViewModel.LoadData();
                        App.ViewModel.LoadSettings();
                    }
                    MainViewModel arg_75_0 = App.ViewModel;
                    IEnumerable<ConnectionViewModel> arg_70_0 = App.ViewModel.Items;
                    if (func == null)
                    {
                        func = new Func<ConnectionViewModel, bool>(this.method_18);
                    }
                    arg_75_0.SelectedConnection = Enumerable.FirstOrDefault<ConnectionViewModel>(arg_70_0, func);
                    if (App.ViewModel.SelectedConnection == null)
                    {
                        MessageBox.Show("The connection name doesn't exists.");
                        base.NavigationService.GoBack();
                        return;
                    }
                }
                if (!base.NavigationContext.QueryString.ContainsKey("local"))
                {
                    this.method_4();
                }
                else
                {
                    this.method_7(this._localPathManager.method_2());
                    this.pivotLocation.Items.Remove(this.pivotRemote);
                    this._isLocalMode = true;
                }
                if (!App.ViewModel.AppSettings.EnableSkyDrive)
                {
                    //this.pivotLocation.get_Items().Remove(this.pivotSkyDrive);
                }
                this._newPage = false;
            }
        }
        private void method_1()
        {
            if (base.ApplicationBar == null)
            {
                base.ApplicationBar = (new ApplicationBar());
            }
            GClass6.smethod_0(base.ApplicationBar);
            GClass6.smethod_1(base.ApplicationBar, "appbar.back.rest.png", "back", new EventHandler(this.btnBack_Click));
            GClass6.smethod_1(base.ApplicationBar, "appbar.copy.rest.png", "copy", new EventHandler(this.btnCopy_Click));
            GClass6.smethod_1(base.ApplicationBar, "appbar.paste.rest.png", "paste", new EventHandler(this.btnPaste_Click));
            GClass6.smethod_1(base.ApplicationBar, "appbar.sync.rest.png", "refresh", new EventHandler(this.btnRefresh_Click));
            GClass6.smethod_2(base.ApplicationBar, "select all", new EventHandler(this.mnuSelectAll_Click));
            GClass6.smethod_2(base.ApplicationBar, "select files", new EventHandler(this.mnuSelectFiles_Click));
            GClass6.smethod_2(base.ApplicationBar, "deselect all", new EventHandler(this.mnuDeselect_Click));
            GClass6.smethod_2(base.ApplicationBar, "create directory", new EventHandler(this.mnuCreateDirectory_Click));
            GClass6.smethod_2(base.ApplicationBar, "delete selected", new EventHandler(this.mnuDelete_Click));
            GClass6.smethod_2(base.ApplicationBar, "load from gallery", new EventHandler(this.mnuLoadFromGallery_Click));
        }
        private void method_2(EventHandler eventHandler_0, EventHandler eventHandler_1)
        {
            GClass6.smethod_0(base.ApplicationBar);
            GClass6.smethod_1(base.ApplicationBar, "appbar.ok.rest.png", "accept", eventHandler_0);
            GClass6.smethod_1(base.ApplicationBar, "appbar.cancel.rest.png", "cancel", eventHandler_1);
        }
        private void method_3(EventHandler eventHandler_0)
        {
            GClass6.smethod_0(base.ApplicationBar);
            GClass6.smethod_1(base.ApplicationBar, "appbar.cancel.rest.png", "cancel", eventHandler_0);
        }
        private void method_4()
        {
            this._smb = new aa();
            this._smb.h(new EventHandler(this._smb_ConnectedCompleted));
            this._smb.i(App.ViewModel.SelectedConnection.Host, App.ViewModel.SelectedConnection.User, App.ViewModel.SelectedConnection.Password);
        }
        private void method_5()
        {
            if (!this._smb.n().k())
            {
                this._smb.h(App.ViewModel.SelectedConnection.Host, App.ViewModel.SelectedConnection.User, App.ViewModel.SelectedConnection.Password);
            }
        }
        private void _smb_ConnectedCompleted(object sender, EventArgs e)
        {
            if (this._smb.p())
            {
                this._service = App.ViewModel.SelectedConnection.Service;
                this._smb.i(new EventHandler<a6>(this._smb_ListFolderCompleted));
                this.method_6(this._service, this._remotePathManager.method_2());
                this.method_7(this._localPathManager.method_2());
                base.ApplicationBar.IsVisible = (true);
                this.pivotLocation.IsEnabled = (true);
                return;
            }
            if (!this._smb.l())
            {
                MessageBox.Show(this._smb.m());
                base.NavigationService.GoBack();
            }
        }
        private void _smb_ListFolderCompleted(object object_0, a6 a6_0)
        {
            if (this._smb.m() == null)
            {
                try
                {
                    List<aw> list = a6_0.d();
                    IEnumerable<aw> arg_3E_0 = list;

                    //if (Explorer.CS$<>9__CachedAnonymousMethodDelegate6 == null)
                    //{
                    //    Explorer.CS$<>9__CachedAnonymousMethodDelegate6 = new Func<aw, bool>(Explorer.smethod_0);
                    //}
                    //IEnumerable<aw> arg_60_0 = Enumerable.Where<aw>(arg_3E_0, Explorer.CS$<>9__CachedAnonymousMethodDelegate6);
                    //if (Explorer.CS$<>9__CachedAnonymousMethodDelegate7 == null)
                    //{
                    //    Explorer.CS$<>9__CachedAnonymousMethodDelegate7 = new Func<aw, string>(Explorer.smethod_1);
                    //}
                    //IOrderedEnumerable<aw> orderedEnumerable = Enumerable.OrderBy<aw, string>(arg_60_0, Explorer.CS$<>9__CachedAnonymousMethodDelegate7);
                    //IEnumerable<aw> arg_84_0 = list;
                    //if (Explorer.CS$<>9__CachedAnonymousMethodDelegate8 == null)
                    //{
                    //    Explorer.CS$<>9__CachedAnonymousMethodDelegate8 = new Func<aw, bool>(Explorer.smethod_2);
                    //}
                    //IEnumerable<aw> arg_A6_0 = Enumerable.Where<aw>(arg_84_0, Explorer.CS$<>9__CachedAnonymousMethodDelegate8);
                    //if (Explorer.CS$<>9__CachedAnonymousMethodDelegate9 == null)
                    //{
                    //    Explorer.CS$<>9__CachedAnonymousMethodDelegate9 = new Func<aw, string>(Explorer.smethod_3);
                    //}
                    //IOrderedEnumerable<aw> orderedEnumerable2 = Enumerable.OrderBy<aw, string>(arg_A6_0, Explorer.CS$<>9__CachedAnonymousMethodDelegate9);

                    IOrderedEnumerable<aw> aws1 = arg_3E_0.Where<aw>((aw aw_0) =>
                    {
                        if (!aw_0.b)
                        {
                            return false;
                        }
                        return aw_0.a != ".";
                    }).OrderBy<aw, string>((aw aw_0) => aw_0.a);
                    IOrderedEnumerable<aw> aws2 = from aw_0 in arg_3E_0 where !aw_0.b orderby aw_0.a select aw_0;
                    this._remoteList.Clear();
                    using (IEnumerator<aw> enumerator = aws1.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            aw current = enumerator.Current;
                            if (current.a != ".." || (current.a == ".." && a6_0.c() != null))
                            {
                                GClass1 gClass = new GClass1();
                                gClass.FileName = current.a;
                                gClass.ImageSrc = "/Images/folder.png";
                                gClass.IsDirectory = true;
                                gClass.Path = a6_0.c();
                                this._remoteList.Add(gClass);
                            }
                        }
                    }
                    using (IEnumerator<aw> enumerator2 = aws2.GetEnumerator())
                    {
                        while (enumerator2.MoveNext())
                        {
                            aw current2 = enumerator2.Current;
                            GClass1 gClass2 = new GClass1();
                            gClass2.FileName = current2.a;
                            gClass2.ImageSrc = "/Images/file.png";
                            gClass2.Path = a6_0.c();
                            gClass2.FileSize = current2.c;
                            this._remoteList.Add(gClass2);
                        }
                    }
                    this.txtLocation.Text = (string.Concat(new string[]
			        {
				        "\\\\",
				        App.ViewModel.SelectedConnection.Host,
				        "\\",
				        this._service,
				        "\\",
				        a6_0.c()
			        }));
                    this.lstBoxMachine.ItemsSource = (this._remoteList);
                    this.pbReading.Visibility = (Visibility)(1);
                    this.pbReading.IsIndeterminate = false;
                    this.pivotLocation.IsEnabled = (true);
                    return;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    base.NavigationService.GoBack();
                    return;
                }
            }
            if (!this._smb.l())
            {
                MessageBox.Show(this._smb.m());
                base.NavigationService.GoBack();
            }
        }
        private void method_6(string string_0, string string_1)
        {
            this.pbReading.Visibility = (Visibility)(0);
            this.pbReading.IsIndeterminate = true;
            this.txtLocation.Text = ("Reading...");
            this.lstBoxMachine.ItemsSource = (null);
            this.pivotLocation.IsEnabled = (false);
            this._smb.h(string_0, string_1);
        }
        private void method_7(string string_0)
        {
            Explorer.Class1 @class = new Explorer.Class1();
            @class.string_0 = string_0;
            @class.explorer_0 = this;
            this.txtLocalLocation.Text = ("Reading...");
            this.lstBoxLocal.ItemsSource = (null);
            this.pivotLocation.IsEnabled = (false);
            BackgroundWorker backgroundWorker = new BackgroundWorker();
            backgroundWorker.DoWork += (new DoWorkEventHandler(@class.method_0));
            backgroundWorker.RunWorkerCompleted += (new RunWorkerCompletedEventHandler(@class.method_1));
            backgroundWorker.RunWorkerAsync();
        }
        private void method_8(string string_0)
        {
            this.pbReading.Visibility = (Visibility)(0);
            this.pbReading.IsIndeterminate = true;
            //this.txtSkyLocation.Text = ("Reading...");
            //this.lstBoxSky.ItemsSource = (null);
            this.pivotLocation.IsEnabled = (false);
            this._skyList.Clear();
            if (!string.IsNullOrEmpty(string_0) && !(string_0 == "me/skydrive"))
            {
                GClass2 gClass = new GClass2();
                gClass.Id = this._skyPathManager.method_4();
                gClass.FileName = "..";
                gClass.ImageSrc = "/Images/folder.png";
                gClass.IsDirectory = true;
                this._skyList.Add(gClass);
                this._skyDriveManager.method_9(string_0 + "/files");
                return;
            }
            this._skyDriveManager.method_9("me/skydrive/files");
        }
        private void SkyDriveListFolder_Completed(object sender, GEventArgs0 e)
        {
            if (string.IsNullOrEmpty(e.string_0))
            {
                this._skyList.AddRange(e.method_0());
                //this.lstBoxSky.ItemsSource = (this._skyList);
            }
            else
            {
                MessageBox.Show(e.string_0);
            }
            this.pbReading.Visibility = (Visibility)(1);
            this.pbReading.IsIndeterminate = false;
            //this.txtSkyLocation.Text = ("");
            this.pivotLocation.IsEnabled = (true);
        }
        private int method_9(string string_0)
        {
            long length;
            using (IsolatedStorageFileStream isolatedStorageFileStream = this._isolatedStore.OpenFile(string_0, (FileMode)3))
            {
                length = isolatedStorageFileStream.Length;
            }
            return (int)length;
        }
        private GEnum0 method_10()
        {
            return this.pivotLocation.SelectedIndex + (this._isLocalMode ? GEnum0.const_1 : GEnum0.const_0);
        }
        private void method_11()
        {
            switch (this.method_10())
            {
                case GEnum0.const_0:
                    this.method_6(this._service, this._remotePathManager.method_2());
                    return;
                case GEnum0.const_1:
                    this.method_7(this._localPathManager.method_2());
                    return;
                case GEnum0.const_2:
                    this.method_8(this._skyPathManager.method_4());
                    return;
                default:
                    return;
            }
        }
        private void lstBoxMachine_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                GClass1 gClass = e.AddedItems[0] as GClass1;
                if (gClass.IsDirectory)
                {
                    if (gClass.FileName != "..")
                    {
                        this._remotePathManager.method_0(gClass.FileName);
                    }
                    else
                    {
                        this._remotePathManager.method_1();
                    }
                    this.method_6(this._service, this._remotePathManager.method_2());
                }
            }
        }
        private void lstBoxLocal_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                GClass1 gClass = e.AddedItems[0] as GClass1;// e.get_AddedItems().get_Item(0) as GClass1;
                if (gClass.IsDirectory)
                {
                    if (gClass.FileName != "..")
                    {
                        this._localPathManager.method_0(gClass.FileName);
                    }
                    else
                    {
                        this._localPathManager.method_1();
                    }
                    this.method_7(this._localPathManager.method_2());
                }
            }
        }
        private void method_12(ListBox listBox_0)
        {
            if (listBox_0.ItemsSource == null)
            {
                return;
            }
            IEnumerator enumerator = listBox_0.ItemsSource.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    GClass1 gClass = (GClass1)enumerator.Current;
                    gClass.Checked = false;
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
        private List<GClass1> method_13(ListBox listBox_0)
        {
            //IEnumerable<GClass1> arg_28_0 = Enumerable.Cast<GClass1>(listBox_0.ItemsSource);
            //if (Explorer.CS$<>9__CachedAnonymousMethodDelegate13 == null)
            //{
            //    Explorer.CS$<>9__CachedAnonymousMethodDelegate13 = new Func<GClass1, bool>(Explorer.smethod_4);
            //}
            //IEnumerable<GClass1> enumerable = Enumerable.Where<GClass1>(arg_28_0, Explorer.CS$<>9__CachedAnonymousMethodDelegate13);
            //return Enumerable.ToList<GClass1>(enumerable);

            IEnumerable<GClass1> gClass1s = listBox_0.ItemsSource.Cast<GClass1>().Where<GClass1>((GClass1 gclass1_0) =>
            {
                if (!gclass1_0.Checked)
                {
                    return false;
                }
                return gclass1_0.FileName != "..";
            });
            return gClass1s.ToList<GClass1>();
        }
        private void method_14()
        {
            switch (this.method_10())
            {
                case GEnum0.const_0:
                    this._clipboard = new GClass0(GEnum0.const_0);
                    this._clipboard.method_3(this._remotePathManager.method_2());
                    this._clipboard.method_5(this.method_13(this.lstBoxMachine));
                    return;
                case GEnum0.const_1:
                    this._clipboard = new GClass0(GEnum0.const_1);
                    this._clipboard.method_3(this._localPathManager.method_2());
                    this._clipboard.method_5(this.method_13(this.lstBoxLocal));
                    return;
                case GEnum0.const_2:
                    this._clipboard = new GClass0(GEnum0.const_2);
                    //this._clipboard.method_5(this.method_13(this.lstBoxSky));
                    return;
                default:
                    return;
            }
        }
        private void btnCopy_Click(object sender, EventArgs e)
        {
            this.method_14();
        }
        private void btnPaste_Click(object sender, EventArgs e)
        {
            if (this._clipboard != null && this._clipboard.method_0() == GEnum0.const_2)
            {
                this._clipboard.method_5((
                    from gclass1_0 in this._clipboard.method_4()
                    where !gclass1_0.IsDirectory
                    select gclass1_0).ToList<GClass1>());
            }
            if (this._IsTrial == "Trial")
            {
                if ((
                    from gclass1_0 in this._clipboard.method_4()
                    where gclass1_0.IsDirectory
                    select gclass1_0).Count<GClass1>() > 0)
                {
                    MessageBox.Show("In trial mode you cannot copy directories.");
                    return;
                }
            }
            if (this._clipboard == null || this._clipboard != null && this._clipboard.method_4().Count == 0)
            {
                MessageBox.Show("Please, select files to copy.");
                return;
            }
            if (this._IsTrial == "Trial")
            {
                if ((
                    from gclass1_0 in this._clipboard.method_4()
                    where gclass1_0.FileSize > 2097152
                    select gclass1_0).Count<GClass1>() > 0)
                {
                    MessageBox.Show("In trial mode you cannot copy files bigger than 2MB.");
                    return;
                }
            }
            if (this.method_10() == GEnum0.const_2 && this._clipboard.method_0() == GEnum0.const_2)
            {
                MessageBox.Show("You cannot copy files from SkyDrive to SkyDrive.");
                return;
            }
            if (this.method_10() == GEnum0.const_2 && this._skyDriveManager == null)
            {
                MessageBox.Show("You must sign in first.");
                return;
            }
            string str = null;
            switch (this.method_10())
            {
                case GEnum0.const_0:
                    {
                        str = this._remotePathManager.method_2();
                        break;
                    }
                case GEnum0.const_1:
                    {
                        str = this._localPathManager.method_2();
                        break;
                    }
                case GEnum0.const_2:
                    {
                        this._clipboard.method_5((
                            from gclass1_0 in this._clipboard.method_4()
                            where !gclass1_0.IsDirectory
                            select gclass1_0).ToList<GClass1>());
                        str = this._skyPathManager.method_4();
                        break;
                    }
            }
            if (this._clipboard.method_2() == str && this._clipboard.method_0() == this.method_10())
            {
                MessageBox.Show("Please, select a different path.");
                return;
            }
            this.StateCanvas.Visibility = Visibility.Visible;
            this.pivotLocation.Visibility = Visibility.Collapsed;
            this.method_3(new EventHandler(this.btnCancelPaste_Click));
            this._iscopying = true;
            this.lbStatus.Text = "Copying files...";
            this._pm = new GClass4(this._clipboard, this._smb, this._service, this._isolatedStore, str);
            this._pm.method_5(this.method_10());
            //this._pm.method_7(this.btnSignSkyDrive.Session);
            PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
            this._pm.method_3(base.Dispatcher);
            this._pm.method_10(this.lbStatus);
            this._pm.method_8().ProgressChanged += new ProgressChangedEventHandler(this.BW_PasteFilesProgressChange);
            this._pm.method_8().RunWorkerCompleted += new RunWorkerCompletedEventHandler(this.BW_PasteCompleted);
            this._pm.method_11();
        }
        private void BW_PasteFilesProgressChange(object sender, ProgressChangedEventArgs e)
        {
            this.pbPaste.Value = ((double)e.ProgressPercentage);
        }
        private void BW_PasteCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.StateCanvas.Visibility = (Visibility)(1);
            this.pivotLocation.Visibility = (Visibility)(0);
            this.pbPaste.Value = (0.0);
            if (!this._isLocalMode)
            {
                if (e.Error != null && !this._smb.l())
                {
                    MessageBox.Show(e.Error.Message);
                }
                else
                {
                    if (!this._smb.l())
                    {
                        this._clipboard = null;
                        this.method_12(this.lstBoxLocal);
                        this.method_12(this.lstBoxMachine);
                        //this.method_12(this.lstBoxSky);
                        this.method_11();
                    }
                }
            }
            else
            {
                if (e.Error != null)
                {
                    MessageBox.Show(e.Error.Message);
                }
                else
                {
                    this._clipboard = null;
                    this.method_12(this.lstBoxLocal);
                    //this.method_12(this.lstBoxSky);
                    this.method_11();
                }
            }
            this.method_1();
            PhoneApplicationService.Current .UserIdleDetectionMode =  (IdleDetectionMode)0;
        }
        private void btnCancelPaste_Click(object sender, EventArgs e)
        {
            if (this._iscopying)
            {
                if (this._pm != null && this._pm.method_8().IsBusy)
                {
                    this._pm.method_12();
                    return;
                }
            }
            else
            {
                this._dm.method_6();
            }
        }
        private void mnuFileLocal_Opened(object sender, RoutedEventArgs e)
        {
            ContextMenu contextMenu = sender as ContextMenu;
            GClass1 gClass = contextMenu.DataContext as GClass1;
            if (gClass.FileName == "..")
            {
                contextMenu.IsOpen = false;
            }
        }
        private void mnuSaveToGallery_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                GClass1 gClass = (sender as MenuItem).DataContext as GClass1;
                using (IsolatedStorageFileStream isolatedStorageFileStream = this._isolatedStore.OpenFile("content\\" + gClass.Path + "\\" + gClass.FileName, (FileMode)3))
                {
                    MediaLibrary mediaLibrary = new MediaLibrary();
                    mediaLibrary.SavePicture(gClass.FileName, isolatedStorageFileStream);
                }
                MessageBox.Show("Successfully saved image");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void mnuLoadFromGallery_Click(object sender, EventArgs e)
        {
            PhotoChooserTask photoChooserTask = new PhotoChooserTask();
            photoChooserTask.Completed += (new EventHandler<PhotoResult>(this.pct_Completed));
            photoChooserTask.Show();
        }
        private void pct_Completed(object object_0, PhotoResult photoResult_0)
        {
            Explorer.Class2 @class = new Explorer.Class2();
            @class.photoResult_0 = photoResult_0;
            @class.explorer_0 = this;
            if (@class.photoResult_0.TaskResult == (TaskResult)1)
            {
                Explorer.Class3 class2 = new Explorer.Class3();
                class2.class2_0 = @class;
                class2.genum0_0 = this.method_10();
                class2.backgroundWorker_0 = new BackgroundWorker();
                this.RenameCanvas.Visibility = (Visibility)(0);
                this.pivotLocation.Visibility = (Visibility)(1);
                this.method_2(new EventHandler(class2.method_0), new EventHandler(this.btnCancelRename_Click));
                this.txtFileName.Text = ("Photo_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".jpg");
                this.txtFileName.Focus();
            }
        }
        protected override void OnNavigatedTo(NavigationEventArgs navigationEventArgs_0)
        {
            if (!this._newPage && !base.NavigationContext.QueryString.ContainsKey("local"))
            {
                this.method_5();
            }
            base.OnNavigatedTo(navigationEventArgs_0);
        }
        private void mnuCreateDirectory_Click(object sender, EventArgs e)
        {
            if (this.method_10() == GEnum0.const_2 && this._skyDriveManager == null)
            {
                MessageBox.Show("Please, sign in on SkyDrive");
                return;
            }
            this.CreateDirCanvas.Visibility = (Visibility)(0);
            this.pivotLocation.Visibility = (Visibility)(1);
            this.method_2(new EventHandler(this.btnCreateDir_Click), new EventHandler(this.btnCancelCreateDir_Click));
            this.txtDirName.Text = ("");
            this.txtDirName.Focus();
        }
        private void btnCreateDir_Click(object sender, EventArgs e)
        {
            if (this.txtDirName.Text == "")
            {
                MessageBox.Show("Please, enter a directory name.");
                return;
            }
            try
            {
                switch (this.method_10())
                {
                    case GEnum0.const_0:
                        {
                            ushort a_ = this._smb.i(this._service);
                            this._smb.h(a_, this._remotePathManager.method_2() + "\\" + this.txtDirName.Text);
                            this._smb.h(a_);
                            break;
                        }
                    case GEnum0.const_1:
                        this._isolatedStore.CreateDirectory("content\\" + this._localPathManager.method_2() + "\\" + this.txtDirName.Text);
                        break;
                    case GEnum0.const_2:
                        this._skyDriveManager.method_11(this._skyPathManager.method_4(), this.txtDirName.Text);
                        return;
                }
                this.method_11();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                this.CreateDirCanvas.Visibility = (Visibility)(1);
                this.pivotLocation.Visibility = (Visibility)(0);
                this.method_1();
            }
        }
        private void btnCancelCreateDir_Click(object sender, EventArgs e)
        {
            this.CreateDirCanvas.Visibility = (Visibility)(1);
            this.pivotLocation.Visibility = (Visibility)(0);
            this.method_1();
        }
        private void mnuDeleteLocal_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Are you sure?", "Delete file", (MessageBoxButton)1) == (MessageBoxResult)1)
            {
                this._clipboard = new GClass0(this.method_10());
                this._clipboard.method_5(new List<GClass1>());
                this._clipboard.method_4().Add((sender as MenuItem).DataContext as GClass1);
                this.method_15();
            }
        }
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            if (this.method_10() == GEnum0.const_2 && this._skyDriveManager == null)
            {
                MessageBox.Show("Please, sign in on SkyDrive.");
                return;
            }
            this.method_11();
        }
        private void mnuDelete_Click(object sender, EventArgs e)
        {
            this.method_14();
            if (MessageBox.Show("Are you sure?", "Delete files", (MessageBoxButton)1) == (MessageBoxResult)1)
            {
                this.method_15();
            }
        }
        private void method_15()
        {
            if (this.method_10() == GEnum0.const_2)
            {
                //IEnumerable<GClass1> arg_37_0 = this._clipboard.method_4();
                //if (Explorer.CS$<>9__CachedAnonymousMethodDelegate2d == null)
                //{
                //    Explorer.CS$<>9__CachedAnonymousMethodDelegate2d = new Func<GClass1, bool>(Explorer.smethod_9);
                //}
                //if (Enumerable.Any<GClass1>(arg_37_0, Explorer.CS$<>9__CachedAnonymousMethodDelegate2d) && MessageBox.Show("You have selected directories to be deleted, note that ShareFolder not show OneNote notes inside directories, and it's possible that one of them contains notes. Do you want to continue?", "ATTENTION", 1) == 2)
                //{
                //    return;
                //}            
                if (this._clipboard.method_4().Any<GClass1>((GClass1 gclass1_0) => gclass1_0.IsDirectory) && MessageBox.Show("You have selected directories to be deleted, note that ShareFolder not show OneNote notes inside directories, and it's possible that one of them contains notes. Do you want to continue?", "ATTENTION", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
                {
                    return;
                }
            }
            this.StateCanvas.Visibility = (Visibility)(0);
            this.pivotLocation.Visibility = (Visibility)(1);
            this.method_3(new EventHandler(this.btnCancelPaste_Click));
            this.lbStatus.Text = ("Deleting files..");
            this._iscopying = false;
            this._dm = new GClass3(this._clipboard, this._smb, this._service, this._isolatedStore);
            //this._dm.method_3(this.btnSignSkyDrive.Session);
            PhoneApplicationService.Current.UserIdleDetectionMode = (IdleDetectionMode)1;
            this._dm.method_4().RunWorkerCompleted += (new RunWorkerCompletedEventHandler(this.BW_PasteCompleted));
            this._dm.method_5();
        }
        private void PhoneApplicationPage_BackKeyPress(object sender, CancelEventArgs e)
        {
            if (this._smb == null)
            {
                return;
            }
            if (MessageBox.Show("Are you sure?", "Disconnect", (MessageBoxButton)1) == (MessageBoxResult)2)
            {
                e.Cancel = (true);
                return;
            }
            if (this._IsSignButtonClicked)
            {
                base.NavigationService.GoBack();
            }
            this._smb.k();
            if (this._smb.p())
            {
                this._smb.j();
            }
        }
        private void mnuView_Click(object sender, RoutedEventArgs e)
        {
            //GClass1 gClass = (sender as MenuItem).DataContext as GClass1;
            //base.get_NavigationService().Navigate(new Uri("/ViewImage.xaml?filename=content\\" + gClass.Path + "\\" + gClass.FileName, 2));
            GClass1 dataContext = (sender as MenuItem).DataContext as GClass1;
            base.NavigationService.Navigate(new Uri(string.Concat("/ViewImage.xaml?filename=content\\", dataContext.Path, "\\", dataContext.FileName), UriKind.Relative));
        }
        private void mnuPlay_Click(object sender, RoutedEventArgs e)
        {
            //GClass1 gClass = (sender as MenuItem).DataContext as GClass1;
            //MediaPlayerLauncher mediaPlayerLauncher = new MediaPlayerLauncher();
            //mediaPlayerLauncher.set_Media(new Uri("content\\" + gClass.Path + "\\" + gClass.FileName, 2));
            //mediaPlayerLauncher.set_Location(2);
            //mediaPlayerLauncher.set_Controls(31);
            //mediaPlayerLauncher.Show();
            GClass1 dataContext = (sender as MenuItem).DataContext as GClass1;
            MediaPlayerLauncher mediaPlayerLauncher = new MediaPlayerLauncher()
            {
                Media = new Uri(string.Concat("content\\", dataContext.Path, "\\", dataContext.FileName), UriKind.Relative),
                Location = MediaLocationType.Data,
                Controls = MediaPlaybackControls.All
            };
            mediaPlayerLauncher.Show();
        }
        private void mnuSaveRingTone_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                GClass1 gClass = (sender as MenuItem).DataContext as GClass1;
                SaveRingtoneTask saveRingtoneTask = new SaveRingtoneTask();
                saveRingtoneTask.Source = (new Uri("isostore:/content\\" + gClass.Path + "\\" + gClass.FileName));
                saveRingtoneTask.Completed += (new EventHandler<TaskEventArgs>(this.saveRingtoneChooser_Completed));
                saveRingtoneTask.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void saveRingtoneChooser_Completed(object sender, TaskEventArgs e)
        {
            switch (e.TaskResult)
            {
                case (TaskResult) 0:
                    MessageBox.Show("Ringtone could not be saved.");
                    break;
                case (TaskResult)1:
                    MessageBox.Show("Ringtone saved!");
                    break;
            }
            if (e.Error != null)
            {
                MessageBox.Show(e.Error.Message);
            }
        }
        private void SkyDriveManager_CreateDirectoryCompleted(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this._skyDriveManager.method_6()))
            {
                MessageBox.Show(this._skyDriveManager.method_6());
            }
            else
            {
                this.method_11();
            }
            this.CreateDirCanvas.Visibility = (Visibility)(1);
            this.pivotLocation.Visibility = (Visibility)(0);
            this.method_1();
        }
        private void SkyDriveManager_RenameCompleted(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this._skyDriveManager.method_6()))
            {
                MessageBox.Show(this._skyDriveManager.method_6());
            }
            else
            {
                this.method_11();
            }
            this.RenameCanvas.Visibility = (Visibility)(1);
            this.pivotLocation.Visibility = (Visibility)(0);
            this.method_1();
        }
        private void SignInButton_SessionChanged(object sender, LiveConnectSessionChangedEventArgs e)
        {
            if (e.Status == LiveConnectSessionStatus.Connected)
            {
                this._skyDriveManager = new GClass5(e.Session);
                this._skyDriveManager.method_2(new EventHandler(this.SkyDriveManager_CreateDirectoryCompleted));
                this._skyDriveManager.method_0(new EventHandler<GEventArgs0>(this.SkyDriveListFolder_Completed));
                this._skyDriveManager.method_4(new EventHandler(this.SkyDriveManager_RenameCompleted));
                this.method_8(null);
                return;
            }
            this._skyDriveManager = null;
            if (this._skyList == null)
            {
                this._skyList = new List<GClass2>();
            }
            else
            {
                this._skyList.Clear();
            }
            this._skyPathManager.method_3();
            //this.lstBoxSky.ItemsSource = (null);
            //this.lstBoxSky.ItemsSource = (this._skyList);
        }

        private void method_16(string string_0)
        {
            this.RenameCanvas.Visibility = (Visibility)(0);
            this.pivotLocation.Visibility = (Visibility)(1);
            this.method_2(new EventHandler(this.btnRename_Click), new EventHandler(this.btnCancelRename_Click));
            this.txtFileName.Text = (string_0);
            this.txtFileName.Focus();
        }
        private void mnuRename_Click(object sender, RoutedEventArgs e)
        {
            this._fileToRename = ((sender as MenuItem).DataContext as GClass1);
            this.method_16(this._fileToRename.FileName);
        }
        private void btnCancelRename_Click(object sender, EventArgs e)
        {
            this.RenameCanvas.Visibility = (Visibility)(1);
            this.pivotLocation.Visibility = (Visibility)(0);
            this.method_1();
        }
        private void btnRename_Click(object sender, EventArgs e)
        {
            if (this.txtFileName.Text == "")
            {
                MessageBox.Show("Please enter new file name");
                return;
            }
            try
            {
                switch (this.method_10())
                {
                    case GEnum0.const_0:
                        {
                            ushort a_ = this._smb.i(this._service);
                            string text = this._fileToRename.Path + "\\" + this.txtFileName.Text;
                            this._smb.h(a_, this._fileToRename.Path + "\\" + this._fileToRename.FileName, text);
                            this._smb.h(a_);
                            break;
                        }
                    case GEnum0.const_1:
                        {
                            string text = this._fileToRename.Path + "\\" + this.txtFileName.Text;
                            this._isolatedStore.MoveFile("content\\" + this._fileToRename.Path + "\\" + this._fileToRename.FileName, "content\\" + text);
                            break;
                        }
                    case GEnum0.const_2:
                        this._skyDriveManager.method_17((this._fileToRename as GClass2).Id, this.txtFileName.Text);
                        return;
                }
                this.method_11();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                this.RenameCanvas.Visibility = (Visibility)(1);
                this.pivotLocation.Visibility = (Visibility)(0);
                this.method_1();
            }
        }
        private void mnuRemoteOptions_Opened(object sender, RoutedEventArgs e)
        {
            ContextMenu contextMenu = sender as ContextMenu;
            GClass1 gClass = contextMenu.DataContext as GClass1;
            if (gClass.FileName == "..")
            {
                contextMenu.IsOpen = false;
            }
        }
        private void method_17(bool bool_0)
        {
            ListBox listBox = null;
            switch (this.method_10())
            {
                case GEnum0.const_0:
                    listBox = this.lstBoxMachine;
                    break;
                case GEnum0.const_1:
                    listBox = this.lstBoxLocal;
                    break;
                case GEnum0.const_2:
                    //listBox = this.lstBoxSky;
                    break;
            }
            if (listBox.ItemsSource == null)
            {
                return;
            }
            IEnumerator enumerator = listBox.ItemsSource.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    GClass1 gClass = (GClass1)enumerator.Current;
                    if (!bool_0 || (bool_0 && !gClass.IsDirectory))
                    {
                        gClass.Checked = true;
                    }
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
        private void mnuSelectAll_Click(object sender, EventArgs e)
        {
            this.method_17(false);
        }
        private void mnuSelectFiles_Click(object sender, EventArgs e)
        {
            this.method_17(true);
        }
        private void mnuDeselect_Click(object sender, EventArgs e)
        {
            ListBox listBox_ = null;
            switch (this.method_10())
            {
                case GEnum0.const_0:
                    listBox_ = this.lstBoxMachine;
                    break;
                case GEnum0.const_1:
                    listBox_ = this.lstBoxLocal;
                    break;
                case GEnum0.const_2:
                    //listBox_ = this.lstBoxSky;
                    break;
            }
            this.method_12(listBox_);
        }
        private void btnBack_Click(object sender, EventArgs e)
        {
            switch (this.method_10())
            {
                case GEnum0.const_0:
                    if (this._remotePathManager.method_2() != null)
                    {
                        this.lstBoxMachine.SelectedIndex = (0);
                        return;
                    }
                    break;
                case GEnum0.const_1:
                    if (this._localPathManager.method_2() != null)
                    {
                        this.lstBoxLocal.SelectedIndex = (0);
                        return;
                    }
                    break;
                case GEnum0.const_2:
                    if (this._skyPathManager.method_4() != "me/skydrive")
                    {
                        //this.lstBoxSky.set_SelectedIndex(0);
                    }
                    break;
                default:
                    return;
            }
        }
        private void btnSignSkyDrive_Click(object sender, RoutedEventArgs e)
        {
            this._IsSignButtonClicked = true;
        }

        private bool method_18(ConnectionViewModel connectionViewModel_0)
        {
            return connectionViewModel_0.Name.ToUpper() == base.NavigationContext.QueryString["ConnectionName"];
        }

        private static bool smethod_0(aw aw_0)
        {
            return aw_0.b && aw_0.a != ".";
        }

        private static string smethod_1(aw aw_0)
        {
            return aw_0.a;
        }

        private static bool smethod_2(aw aw_0)
        {
            return !aw_0.b;
        }

        private static string smethod_3(aw aw_0)
        {
            return aw_0.a;
        }

        private static bool smethod_4(GClass1 gclass1_0)
        {
            return gclass1_0.Checked && gclass1_0.FileName != "..";
        }

        private static bool smethod_5(GClass1 gclass1_0)
        {
            return !gclass1_0.IsDirectory;
        }

        private static bool smethod_6(GClass1 gclass1_0)
        {
            return gclass1_0.IsDirectory;
        }

        private static bool smethod_7(GClass1 gclass1_0)
        {
            return gclass1_0.FileSize > 2097152;
        }

        private static bool smethod_8(GClass1 gclass1_0)
        {
            return !gclass1_0.IsDirectory;
        }

        private static bool smethod_9(GClass1 gclass1_0)
        {
            return gclass1_0.IsDirectory;
        }
    }
}
